// axios二次封装
import axios from "axios";
import nprogress from "nprogress";
import "nprogress/nprogress.css";

const requests = axios.create({
    baseURL: "/api",
    timeout: 5000, // 超时时间
});

// 请求拦截器
requests.interceptors.request.use(function (config) {
    nprogress.start();
    return config;
});

// 响应拦截器
requests.interceptors.response.use(function (response) {
    nprogress.done();
    return response.data;
}, function (error) {
    console.log(error);
    return Promise.resolve(new Error("fail"));
});

export default requests;
